package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexVo;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import com.atguigu.tingshu.vo.search.HomePage;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;

    @GetMapping("/channel/{category1Id}")
    public Result<List<HomePage>> channel(@PathVariable Long category1Id) {
        List<HomePage> list = searchService.channel(category1Id);
        return Result.ok(list);
    }

    @PostMapping
    public Result<AlbumSearchResponseVo> search(@RequestBody AlbumIndexQuery albumIndexQuery) {
        AlbumSearchResponseVo albumSearchResponseVo = searchService.search(albumIndexQuery);
        return Result.ok(albumSearchResponseVo);
    }

    @GetMapping("/findRankingList/{category1Id}/{sortFiled}")
    public Result<List<AlbumInfoIndexVo>> findRankingList(
            @PathVariable Long category1Id,
            @PathVariable String sortFiled) {
        List<AlbumInfoIndexVo> list = searchService.findRankingList(category1Id, sortFiled);
        return Result.ok(list);
    }

    @GetMapping("/completeSuggest/{prefix}")
    public Result<List<String>> completeSuggest(@PathVariable String prefix) {
        List<String> list = searchService.completeSuggest(prefix);
        return Result.ok(list);
    }

    @PutMapping("/updateTop")
    public Result updateTop() {
        this.searchService.updateTop();
        return Result.ok();
    }
}

